<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "adodb" . EW_PATH_DELIMITER . "adodb.inc.php" ?>
<?php include "phpfn7.php" ?>
<?php include "zmenuinfo.php" ?>
<?php include "usuariosinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$zmenu_edit = new czmenu_edit();
$Page =& $zmenu_edit;

// Page init
$zmenu_edit->Page_Init();

// Page main
$zmenu_edit->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var zmenu_edit = new ew_Page("zmenu_edit");

// page properties
zmenu_edit.PageID = "edit"; // page ID
zmenu_edit.FormID = "fzmenuedit"; // form ID
var EW_PAGE_ID = zmenu_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
zmenu_edit.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
zmenu_edit.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
zmenu_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
zmenu_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $zmenu->TableCaption() ?><br><br>
<a href="<?php echo $zmenu->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$zmenu_edit->ShowMessage();
?>
<form name="fzmenuedit" id="fzmenuedit" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return zmenu_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="zmenu">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($zmenu->id->Visible) { // id ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $zmenu->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $zmenu->id->ViewAttributes() ?>><?php echo $zmenu->id->EditValue ?></div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($zmenu->id->CurrentValue) ?>">
</span><?php echo $zmenu->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($zmenu->Titulo->Visible) { // Titulo ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->Titulo->FldCaption() ?></td>
		<td<?php echo $zmenu->Titulo->CellAttributes() ?>><span id="el_Titulo">
<input type="text" name="x_Titulo" id="x_Titulo" title="<?php echo $zmenu->Titulo->FldTitle() ?>" size="30" value="<?php echo $zmenu->Titulo->EditValue ?>"<?php echo $zmenu->Titulo->EditAttributes() ?>>
</span><?php echo $zmenu->Titulo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($zmenu->Destino->Visible) { // Destino ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->Destino->FldCaption() ?></td>
		<td<?php echo $zmenu->Destino->CellAttributes() ?>><span id="el_Destino">
<select id="x_Destino" name="x_Destino" title="<?php echo $zmenu->Destino->FldTitle() ?>"<?php echo $zmenu->Destino->EditAttributes() ?>>
<?php
if (is_array($zmenu->Destino->EditValue)) {
	$arwrk = $zmenu->Destino->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($zmenu->Destino->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $zmenu->Destino->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($zmenu->Url->Visible) { // Url ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->Url->FldCaption() ?></td>
		<td<?php echo $zmenu->Url->CellAttributes() ?>><span id="el_Url">
<input type="text" name="x_Url" id="x_Url" title="<?php echo $zmenu->Url->FldTitle() ?>" size="30" value="<?php echo $zmenu->Url->EditValue ?>"<?php echo $zmenu->Url->EditAttributes() ?>>
</span><?php echo $zmenu->Url->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($zmenu->Orden->Visible) { // Orden ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->Orden->FldCaption() ?></td>
		<td<?php echo $zmenu->Orden->CellAttributes() ?>><span id="el_Orden">
<select id="x_Orden" name="x_Orden" title="<?php echo $zmenu->Orden->FldTitle() ?>"<?php echo $zmenu->Orden->EditAttributes() ?>>
<?php
if (is_array($zmenu->Orden->EditValue)) {
	$arwrk = $zmenu->Orden->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($zmenu->Orden->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $zmenu->Orden->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($zmenu->Habilitado->Visible) { // Habilitado ?>
	<tr<?php echo $zmenu->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $zmenu->Habilitado->FldCaption() ?></td>
		<td<?php echo $zmenu->Habilitado->CellAttributes() ?>><span id="el_Habilitado">
<div id="tp_x_Habilitado" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_Habilitado[]" id="x_Habilitado[]" title="<?php echo $zmenu->Habilitado->FldTitle() ?>" value="{value}"<?php echo $zmenu->Habilitado->EditAttributes() ?>></div>
<div id="dsl_x_Habilitado" repeatcolumn="5">
<?php
$arwrk = $zmenu->Habilitado->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($zmenu->Habilitado->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="checkbox" name="x_Habilitado[]" id="x_Habilitado[]" title="<?php echo $zmenu->Habilitado->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $zmenu->Habilitado->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $zmenu->Habilitado->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$zmenu_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class czmenu_edit {

	// Page ID
	var $PageID = 'edit';

	// Table name
	var $TableName = 'menu';

	// Page object name
	var $PageObjName = 'zmenu_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $zmenu;
		if ($zmenu->UseTokenInUrl) $PageUrl .= "t=" . $zmenu->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $zmenu;
		if ($zmenu->UseTokenInUrl) {
			if ($objForm)
				return ($zmenu->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($zmenu->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function czmenu_edit() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (zmenu)
		$GLOBALS["zmenu"] = new czmenu();

		// Table object (usuarios)
		$GLOBALS['usuarios'] = new cusuarios();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'menu', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $zmenu;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter;
	var $sDbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $zmenu;

		// Load key from QueryString
		if (@$_GET["id"] <> "")
			$zmenu->id->setQueryStringValue($_GET["id"]);
		if (@$_POST["a_edit"] <> "") {
			$zmenu->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

			// Validate form
			if (!$this->ValidateForm()) {
				$zmenu->CurrentAction = ""; // Form error, reset action
				$this->setMessage($gsFormError);
				$zmenu->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$zmenu->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($zmenu->id->CurrentValue == "")
			$this->Page_Terminate("zmenulist.php"); // Invalid key, return to list
		switch ($zmenu->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("zmenulist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$zmenu->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $zmenu->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$zmenu->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$zmenu->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $zmenu;

		// Get upload data
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $zmenu;
		$zmenu->id->setFormValue($objForm->GetValue("x_id"));
		$zmenu->Titulo->setFormValue($objForm->GetValue("x_Titulo"));
		$zmenu->Destino->setFormValue($objForm->GetValue("x_Destino"));
		$zmenu->Url->setFormValue($objForm->GetValue("x_Url"));
		$zmenu->Orden->setFormValue($objForm->GetValue("x_Orden"));
		$zmenu->Habilitado->setFormValue($objForm->GetValue("x_Habilitado"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $zmenu;
		$this->LoadRow();
		$zmenu->id->CurrentValue = $zmenu->id->FormValue;
		$zmenu->Titulo->CurrentValue = $zmenu->Titulo->FormValue;
		$zmenu->Destino->CurrentValue = $zmenu->Destino->FormValue;
		$zmenu->Url->CurrentValue = $zmenu->Url->FormValue;
		$zmenu->Orden->CurrentValue = $zmenu->Orden->FormValue;
		$zmenu->Habilitado->CurrentValue = $zmenu->Habilitado->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $zmenu;
		$sFilter = $zmenu->KeyFilter();

		// Call Row Selecting event
		$zmenu->Row_Selecting($sFilter);

		// Load SQL based on filter
		$zmenu->CurrentFilter = $sFilter;
		$sSql = $zmenu->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$zmenu->Row_Selected($rs);
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $zmenu;
		$zmenu->id->setDbValue($rs->fields('id'));
		$zmenu->Titulo->setDbValue($rs->fields('Titulo'));
		$zmenu->Destino->setDbValue($rs->fields('Destino'));
		$zmenu->Url->setDbValue($rs->fields('Url'));
		$zmenu->Orden->setDbValue($rs->fields('Orden'));
		$zmenu->Habilitado->setDbValue($rs->fields('Habilitado'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $zmenu;

		// Initialize URLs
		// Call Row_Rendering event

		$zmenu->Row_Rendering();

		// Common render codes for all row types
		// id

		$zmenu->id->CellCssStyle = ""; $zmenu->id->CellCssClass = "";
		$zmenu->id->CellAttrs = array(); $zmenu->id->ViewAttrs = array(); $zmenu->id->EditAttrs = array();

		// Titulo
		$zmenu->Titulo->CellCssStyle = ""; $zmenu->Titulo->CellCssClass = "";
		$zmenu->Titulo->CellAttrs = array(); $zmenu->Titulo->ViewAttrs = array(); $zmenu->Titulo->EditAttrs = array();

		// Destino
		$zmenu->Destino->CellCssStyle = ""; $zmenu->Destino->CellCssClass = "";
		$zmenu->Destino->CellAttrs = array(); $zmenu->Destino->ViewAttrs = array(); $zmenu->Destino->EditAttrs = array();

		// Url
		$zmenu->Url->CellCssStyle = ""; $zmenu->Url->CellCssClass = "";
		$zmenu->Url->CellAttrs = array(); $zmenu->Url->ViewAttrs = array(); $zmenu->Url->EditAttrs = array();

		// Orden
		$zmenu->Orden->CellCssStyle = ""; $zmenu->Orden->CellCssClass = "";
		$zmenu->Orden->CellAttrs = array(); $zmenu->Orden->ViewAttrs = array(); $zmenu->Orden->EditAttrs = array();

		// Habilitado
		$zmenu->Habilitado->CellCssStyle = ""; $zmenu->Habilitado->CellCssClass = "";
		$zmenu->Habilitado->CellAttrs = array(); $zmenu->Habilitado->ViewAttrs = array(); $zmenu->Habilitado->EditAttrs = array();
		if ($zmenu->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$zmenu->id->ViewValue = $zmenu->id->CurrentValue;
			$zmenu->id->CssStyle = "";
			$zmenu->id->CssClass = "";
			$zmenu->id->ViewCustomAttributes = "";

			// Titulo
			$zmenu->Titulo->ViewValue = $zmenu->Titulo->CurrentValue;
			$zmenu->Titulo->CssStyle = "";
			$zmenu->Titulo->CssClass = "";
			$zmenu->Titulo->ViewCustomAttributes = "";

			// Destino
			if (strval($zmenu->Destino->CurrentValue) <> "") {
				switch ($zmenu->Destino->CurrentValue) {
					case "_new":
						$zmenu->Destino->ViewValue = "Nueva Pagina";
						break;
					case "_self":
						$zmenu->Destino->ViewValue = "Misma Pagina";
						break;
					default:
						$zmenu->Destino->ViewValue = $zmenu->Destino->CurrentValue;
				}
			} else {
				$zmenu->Destino->ViewValue = NULL;
			}
			$zmenu->Destino->CssStyle = "";
			$zmenu->Destino->CssClass = "";
			$zmenu->Destino->ViewCustomAttributes = "";

			// Url
			$zmenu->Url->ViewValue = $zmenu->Url->CurrentValue;
			$zmenu->Url->CssStyle = "";
			$zmenu->Url->CssClass = "";
			$zmenu->Url->ViewCustomAttributes = "";

			// Orden
			if (strval($zmenu->Orden->CurrentValue) <> "") {
				switch ($zmenu->Orden->CurrentValue) {
					case "1":
						$zmenu->Orden->ViewValue = "1";
						break;
					case "2":
						$zmenu->Orden->ViewValue = "2";
						break;
					case "3":
						$zmenu->Orden->ViewValue = "3";
						break;
					case "4":
						$zmenu->Orden->ViewValue = "4";
						break;
					case "5":
						$zmenu->Orden->ViewValue = "5";
						break;
					case "6":
						$zmenu->Orden->ViewValue = "6";
						break;
					default:
						$zmenu->Orden->ViewValue = $zmenu->Orden->CurrentValue;
				}
			} else {
				$zmenu->Orden->ViewValue = NULL;
			}
			$zmenu->Orden->CssStyle = "";
			$zmenu->Orden->CssClass = "";
			$zmenu->Orden->ViewCustomAttributes = "";

			// Habilitado
			if (strval($zmenu->Habilitado->CurrentValue) <> "") {
				$zmenu->Habilitado->ViewValue = "";
				$arwrk = explode(",", strval($zmenu->Habilitado->CurrentValue));
				for ($ari = 0; $ari < count($arwrk); $ari++) {
					switch (trim($arwrk[$ari])) {
						case "1":
							$zmenu->Habilitado->ViewValue .= "Habilitado";
							break;
						default:
							$zmenu->Habilitado->ViewValue .= trim($arwrk[$ari]);
					}
					if ($ari < count($arwrk)-1) $zmenu->Habilitado->ViewValue .= ew_ViewOptionSeparator($ari);
				}
			} else {
				$zmenu->Habilitado->ViewValue = NULL;
			}
			$zmenu->Habilitado->CssStyle = "";
			$zmenu->Habilitado->CssClass = "";
			$zmenu->Habilitado->ViewCustomAttributes = "";

			// id
			$zmenu->id->HrefValue = "";
			$zmenu->id->TooltipValue = "";

			// Titulo
			$zmenu->Titulo->HrefValue = "";
			$zmenu->Titulo->TooltipValue = "";

			// Destino
			$zmenu->Destino->HrefValue = "";
			$zmenu->Destino->TooltipValue = "";

			// Url
			$zmenu->Url->HrefValue = "";
			$zmenu->Url->TooltipValue = "";

			// Orden
			$zmenu->Orden->HrefValue = "";
			$zmenu->Orden->TooltipValue = "";

			// Habilitado
			$zmenu->Habilitado->HrefValue = "";
			$zmenu->Habilitado->TooltipValue = "";
		} elseif ($zmenu->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// id
			$zmenu->id->EditCustomAttributes = "";
			$zmenu->id->EditValue = $zmenu->id->CurrentValue;
			$zmenu->id->CssStyle = "";
			$zmenu->id->CssClass = "";
			$zmenu->id->ViewCustomAttributes = "";

			// Titulo
			$zmenu->Titulo->EditCustomAttributes = "";
			$zmenu->Titulo->EditValue = ew_HtmlEncode($zmenu->Titulo->CurrentValue);

			// Destino
			$zmenu->Destino->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("_new", "Nueva Pagina");
			$arwrk[] = array("_self", "Misma Pagina");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$zmenu->Destino->EditValue = $arwrk;

			// Url
			$zmenu->Url->EditCustomAttributes = "";
			$zmenu->Url->EditValue = ew_HtmlEncode($zmenu->Url->CurrentValue);

			// Orden
			$zmenu->Orden->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("1", "1");
			$arwrk[] = array("2", "2");
			$arwrk[] = array("3", "3");
			$arwrk[] = array("4", "4");
			$arwrk[] = array("5", "5");
			$arwrk[] = array("6", "6");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$zmenu->Orden->EditValue = $arwrk;

			// Habilitado
			$zmenu->Habilitado->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("1", "Habilitado");
			$zmenu->Habilitado->EditValue = $arwrk;

			// Edit refer script
			// id

			$zmenu->id->HrefValue = "";

			// Titulo
			$zmenu->Titulo->HrefValue = "";

			// Destino
			$zmenu->Destino->HrefValue = "";

			// Url
			$zmenu->Url->HrefValue = "";

			// Orden
			$zmenu->Orden->HrefValue = "";

			// Habilitado
			$zmenu->Habilitado->HrefValue = "";
		}

		// Call Row Rendered event
		if ($zmenu->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$zmenu->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $zmenu;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $sFormCustomError;
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $zmenu;
		$sFilter = $zmenu->KeyFilter();
		$zmenu->CurrentFilter = $sFilter;
		$sSql = $zmenu->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold =& $rs->fields;
			$rsnew = array();

			// Titulo
			$zmenu->Titulo->SetDbValueDef($rsnew, $zmenu->Titulo->CurrentValue, NULL, FALSE);

			// Destino
			$zmenu->Destino->SetDbValueDef($rsnew, $zmenu->Destino->CurrentValue, NULL, FALSE);

			// Url
			$zmenu->Url->SetDbValueDef($rsnew, $zmenu->Url->CurrentValue, NULL, FALSE);

			// Orden
			$zmenu->Orden->SetDbValueDef($rsnew, $zmenu->Orden->CurrentValue, NULL, FALSE);

			// Habilitado
			$zmenu->Habilitado->SetDbValueDef($rsnew, $zmenu->Habilitado->CurrentValue, NULL, FALSE);

			// Call Row Updating event
			$bUpdateRow = $zmenu->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
				$conn->raiseErrorFn = 'ew_ErrorFn';
				$EditRow = $conn->Execute($zmenu->UpdateSQL($rsnew));
				$conn->raiseErrorFn = '';
			} else {
				if ($zmenu->CancelMessage <> "") {
					$this->setMessage($zmenu->CancelMessage);
					$zmenu->CancelMessage = "";
				} else {
					$this->setMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$zmenu->Row_Updated($rsold, $rsnew);
		$rs->Close();
		return $EditRow;
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
